home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / bash-1.12 / dist / test-suite / precedence < prev   
Encoding:
Text File  |  1991-08-04  |  1.2 KB  |  80 lines

  1. # @(#)precedence_test 1.0 91/07/24 Maarten Litmaath
  2. # test of relative precedences for `&&' and `||' operators
  3.  
  4. echo "\`Say' echos its argument. Its return value is of no interest."
  5. case `echo -n` in
  6.   '') function Say () { echo -n "$*" ; } ;;
  7.    *) function Say () { echo "$*\c" ; } ;;
  8. esac
  9.  
  10. echo "\`Truth' echos its argument and returns a TRUE result."
  11. function Truth () {
  12.   Say $1;
  13.   return 0;
  14. }
  15.  
  16. echo "\`False' echos its argument and returns a FALSE result."
  17. function False () {
  18.   Say $1;
  19.   return 1;
  20. }
  21.  
  22. echo ""
  23.  
  24. cmd1='$open $test1 && $test2 $close || $test3'
  25. cmd2='$test1 || $open $test2 && $test3 $close'
  26.  
  27. grouping_sh=
  28. grouping_C='( )'
  29.  
  30. test3='Say 3'
  31.  
  32. for i in 1 2
  33. do
  34.     eval proto=\$cmd$i
  35.  
  36.     for test1 in 'Truth 1' 'False 1'
  37.     do
  38.         for test2 in 'Truth 2' 'False 2'
  39.         do
  40.             for precedence in sh C
  41.             do
  42.                 eval set x \$grouping_$precedence
  43.                 shift
  44.                 open=${1-' '}
  45.                 close=${2-' '}
  46.                 eval cmd=\""$proto"\"
  47.                 Say "$cmd   output="
  48.                 output=`eval "$cmd"`
  49.                 Say "$output"
  50.                 read correct || {
  51.                     echo 'Input fubar.  Abort.' >&2
  52.                     exit 1
  53.                 }
  54.                 test "X$output" = "X$correct" ||
  55.                     echo "   correct=$correct"
  56.                 echo ''
  57.             done
  58.  
  59.             echo ''
  60.         done
  61.     done
  62. done << EOF
  63. 12
  64. 12
  65. 123
  66. 123
  67. 13
  68. 13
  69. 13
  70. 13
  71. 13
  72. 1
  73. 13
  74. 1
  75. 123
  76. 123
  77. 12
  78. 12
  79. EOF
  80.